package com.wulijie.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author cui
 * @Data
 */
public class SpecificObserver implements WeatherObserver {
    private List<Observer> observers;
    private float humidity;
    private float temperature;

    public SpecificObserver() {
        observers = new ArrayList<>();
    }

    @Override
    public void register(Observer observer) {
        this.observers.add(observer);
    }

    public void setData(float humidity, float temperature) {
        this.humidity = humidity;
        this.temperature = temperature;
        notifySite();
    }

    @Override
    public void notifySite() {
        for (Observer observer : this.observers) {
            observer.update(this.humidity, this.temperature);
        }
    }

    @Override
    public void remove(Observer observer) {
        this.observers.remove(observer);
    }
}
